home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / console / svgatext.3 / svgatext / SVGATextMode-1.3 / cfglex.l < prev    next >
Encoding:
Lex Description  |  1996-03-24  |  7.0 KB  |  231 lines

  1. %{
  2. /*
  3.   SVGATextMode -- An SVGA textmode manipulation/enhancement tool
  4.  
  5.   Copyright (C) 1995  Koen Gadeyne
  6.  
  7.   This program is free software; you can redistribute it and/or modify
  8.   it under the terms of the GNU General Public License as published by
  9.   the Free Software Foundation; either version 2 of the License, or
  10.   (at your option) any later version.
  11.  
  12.   This program is distributed in the hope that it will be useful,
  13.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.   GNU General Public License for more details.
  16.  
  17.   You should have received a copy of the GNU General Public License
  18.   along with this program; if not, write to the Free Software
  19.   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.  
  22.   Based on earlier work done for svgalib by Stephen Lee.
  23. */
  24.  
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include "cfg_structs.h"
  28. #include "chipset.h"
  29. #ifdef DOS
  30. #  include "y_tab.h"
  31. #else
  32. #  include "y.tab.h"
  33. #endif
  34. #include "messages.h"
  35. #include "misc.h"
  36.  
  37. #define unquote_yytext  ( *(yytext+(yyleng-1))='\0' , (yytext+1) )   /* works, but doesn't allow spaces */
  38. #define unquote1_yytext  ( *(yytext+(yyleng-1))='\0' , (yytext) )   /* works, but doesn't allow spaces */
  39.  
  40. /* this is a kludge. There should be a way to get rid of the quotes in LEX itself */
  41. #define unquote_strdup_yytext  ( unqstr=safe_strdup(yytext) , \
  42.                                  sscanf(yytext, " \"%s ", unqstr) , \
  43.                                  (*(unqstr+(strlen(unqstr)-1))='\0') , \
  44.                                  unqstr \
  45.                                )
  46. #define yyerror(s) PERROR(("%s on line %d of config file\n", (s), line_num));
  47.  
  48. int find_token(t_str_token *rec, char *ch_str);
  49. int find_token_sh(t_str_token *rec, char *ch_str);
  50. extern void *safe_strdup(const char *s);
  51.  
  52. int line_num = 1;
  53. char *unqstr;
  54.  
  55.  
  56.  
  57. %}
  58.  
  59. /* These options reduce the warnings when compiling with -Wall, but need at least flex 2.5
  60. %option noyywrap
  61. %option nounput
  62. */ 
  63.  
  64. delim        [ \t]
  65. ws        {delim}+
  66. letter        [A-Za-z]
  67. int        [0-9]+
  68. float        {int}(\.{int})?([Ee][+\-]?{int})?
  69. comment        \#[^\n]*
  70. qstring        \"[^\"\n]*["\n]
  71. beginline    ^{delim}*
  72.  
  73. %x X_CHIPSET X_CLOCKCHIP X_OPTION X_MODELINE X_FONTSPEC X_QSTR X_FLT X_SYNC
  74. %x X_INT X_INTRANGE X_FONTSELECT
  75.  
  76. %%
  77.  
  78.  
  79. {ws}|{comment} |
  80. <X_CHIPSET>{ws}|{comment} |
  81. <X_CLOCKCHIP>{ws}|{comment} |
  82. <X_OPTION>{ws}|{comment} |
  83. <X_MODELINE>{ws}|{comment} |
  84. <X_QSTR>{ws}|{comment} |
  85. <X_FLT>{ws}|{comment} |
  86. <X_SYNC>{ws}|{comment} |
  87. <X_INTRANGE>{ws}|{comment} |
  88. <X_INT>{ws}|{comment} |
  89. <X_FONTSELECT>{ws}|{comment} |
  90. <X_FONTSPEC>{ws}|{comment}    { /* ignore blanks and comments */ }
  91.  
  92. {beginline}clockchip      { BEGIN(X_CLOCKCHIP); }
  93. {beginline}chipset        { BEGIN(X_CHIPSET); }
  94. {beginline}option         { BEGIN(X_OPTION); }
  95. {beginline}modeline       { BEGIN(X_MODELINE); return(MODELINE); }
  96. {beginline}defaultmode    { BEGIN(X_QSTR); return(DFLTMODE); }
  97. {beginline}resetprog      { BEGIN(X_QSTR); return (RESETPROG); }
  98. {beginline}clockprog      { BEGIN(X_QSTR); return (CLOCKPROG); }
  99. {beginline}fontprog       { BEGIN(X_QSTR); return (FONTPROG); }
  100. {beginline}fontpath       { BEGIN(X_QSTR); return (FONTPATH); }
  101. {beginline}terminals      { BEGIN(X_QSTR); return (TERMINALS); }
  102. {beginline}clocks         { BEGIN(X_FLT); return (CLOCKS); }
  103. {beginline}dacspeed       { BEGIN(X_FLT); return (DACSPEED); }
  104. {beginline}mclk           { BEGIN(X_FLT); return (MCLK); }
  105. {beginline}refclk         { BEGIN(X_FLT); return (REFCLK); }
  106. {beginline}horizsync      { BEGIN(X_SYNC); return (HORIZSYNC); }
  107. {beginline}vertrefresh    { BEGIN(X_SYNC); return (VERTREFRESH); }
  108. {beginline}cursor         { BEGIN(X_INTRANGE); return (CURSOR); }
  109. {beginline}underline      { BEGIN(X_INT); return(UNDERLINE); }
  110. {beginline}bordercolor    { BEGIN(X_INT); return(BORDERCOL); }
  111. {beginline}fontselect     { BEGIN(X_FONTSELECT); return(FONTSELECT); }
  112. {beginline}echo           { BEGIN(X_QSTR); }
  113.  
  114. {beginline}{qstring}      { 
  115.                             BEGIN(X_MODELINE);
  116.                             yylval.sval = unquote_strdup_yytext;
  117.                             return(SMODELINE);
  118.                           }
  119.  
  120.  
  121. <X_CHIPSET>{qstring}    { yylval.ival = find_token(ChipsetRec, unquote_yytext); return (CHIPSETTYPE); }
  122.  
  123. <X_CLOCKCHIP>{qstring}  { yylval.ival = find_token(ClockchipRec, unquote_yytext); return (CLOCKCHIPTYPE); }
  124.  
  125. <X_OPTION>{qstring}     { yylval.ival = find_token_sh(OptionRec, unquote_yytext); return (OPTIONDEF); }
  126.  
  127. <X_MODELINE>font    { return (FONT); }
  128. <X_MODELINE>\+hsync    { yylval.ival = POS ; return (HSYNC); }
  129. <X_MODELINE>\+vsync    { yylval.ival = POS ; return (VSYNC); }
  130. <X_MODELINE>\-hsync    { yylval.ival = NEG ; return (HSYNC); }
  131. <X_MODELINE>\-vsync    { yylval.ival = NEG ; return (VSYNC); }
  132. <X_MODELINE>interlace    { yylval.ival = ATTR_INTERLACE  ; return (FLAGS); }
  133. <X_MODELINE>doublescan    { yylval.ival = ATTR_DOUBLESCAN ; return (FLAGS); }
  134. <X_MODELINE>{qstring}    { yylval.sval = safe_strdup(unquote_yytext); return (QSTRING); }
  135. <X_MODELINE>{int}    { yylval.ival = atoi(yytext); return (INT); }
  136. <X_MODELINE>{float}    { yylval.fval = atof(yytext); return (FLOAT); }
  137. <X_MODELINE>[x\*]    { return (DIM); }
  138.  
  139. <X_QSTR>{qstring}    { yylval.sval = safe_strdup(unquote_yytext); return (QSTRING); }
  140.  
  141. <X_FLT>{float}        { yylval.fval = atof(yytext); return (FLOAT); }
  142.  
  143. <X_SYNC>{float}        { yylval.fval = atof(yytext); return (FLOAT); }
  144. <X_SYNC>[,-]        { return *yytext; }
  145.  
  146. <X_INTRANGE>{int}    { yylval.ival = atoi(yytext); return (INT); }
  147. <X_INTRANGE>[-]        { return *yytext; }
  148.  
  149. <X_INT>{int}        { yylval.ival = atoi(yytext); return (INT); }
  150.  
  151. <X_FONTSELECT>{qstring}    { yylval.sval = safe_strdup(unquote_yytext); return (QSTRING); }
  152. <X_FONTSELECT>{int}    { yylval.ival = atoi(yytext); return (INT); }
  153. <X_FONTSELECT>[x\*]    { return (DIM); }
  154. <X_FONTSELECT>,     { /* eat comma's */ }
  155.  
  156. \n |
  157. <X_CHIPSET>\n |
  158. <X_CLOCKCHIP>\n |
  159. <X_OPTION>\n |
  160. <X_FONTSPEC>\n |
  161. <X_QSTR>\n |
  162. <X_FLT>\n |
  163. <X_SYNC>\n |
  164. <X_INTRANGE>\n |
  165. <X_INT>\n |
  166. <X_FONTSELECT>\n |
  167. <X_MODELINE>\n    {  BEGIN 0; line_num++; return *yytext; }
  168.  
  169.  
  170.  
  171.  
  172. . |
  173. <X_CHIPSET>. |
  174. <X_CLOCKCHIP>. |
  175. <X_OPTION>. |
  176. <X_FONTSPEC>. |
  177. <X_QSTR>. |
  178. <X_FLT>. |
  179. <X_SYNC>. |
  180. <X_INTRANGE>. |
  181. <X_INT>. |
  182. <X_FONTSELECT>. |
  183. <X_MODELINE>.    { yyerror("Unknown token"); }
  184.  
  185.  
  186. %%
  187.  
  188. int find_token(t_str_token *rec, char *ch_str)
  189. {
  190.   int i = 0;
  191.   while (rec[i].name!=ENDREC)
  192.   {
  193.     if (!strcasecmp(rec[i].name_str,ch_str))
  194.     {
  195.       if (i != rec[i].name)
  196.       {
  197.         PERROR(("Internal error in cfglex.l: rec[].name/offset mismatch: i=%d, rec[i].name=%d, configfile line %d\n",\
  198.                  i, rec[i].name, line_num));
  199.       }
  200.       return i;
  201.     }
  202.     i++;
  203.   }
  204.   yyerror("Unknown token");
  205.   return ENDREC;
  206. }
  207.  
  208. int find_token_sh(t_str_token *rec, char *ch_str)
  209. {
  210.   int i = 0;
  211.   while (rec[i].name!=ENDREC)
  212.   {
  213.     if (!strcasecmp(rec[i].name_str,ch_str))
  214.     {
  215.       if ((1<<i) != rec[i].name)
  216.       {
  217.         PERROR(("Internal error in cfglex.l: rec[].name/offset mismatch: 1<<i=%d, rec[i].name=%d, configfile line %d\n",\
  218.                  1<<i, rec[i].name, line_num));
  219.       }
  220.       return 1<<i;
  221.     }
  222.     i++;
  223.   }
  224.   yyerror("Unknown token");
  225.   return ENDREC;
  226. }
  227.  
  228. #ifndef yywrap
  229. int yywrap() {return 1;}
  230. #endif
  231.